export function phoneEncrypt(phone) { //11位手机号加密
    return phone.substring(0, 3) + '****' + phone.substring(7, 11)
}

export function keepPoint(str, keepLen) { //保留keepLen位小数 截取
    if (str || str === 0) {
        str = str.toString()
        if (str.indexOf('.') > -1) { //存在小数点
            let pointBehind = str.split('.')[1] //小数点后的字符串
            let pointLength = pointBehind.toString().length //小数点后的位数
            let addLength = ''; //增加的小数点字符串
            if (pointLength <= keepLen) { //小数点后长度小于需要保留的小数点位数
                let addStrLen = keepLen - pointLength; //需要增加小数点后的位数
                for (let i = 0; i < addStrLen; i++) {
                    addLength += '0'
                }
                return str + addLength;
            } else {
                let arr = str.split('.')
                return arr[0] + '.' + arr[1].substring(0, keepLen)
            }
        } else {
            let addLen = ''
            for (let i = 0; i < keepLen; i++) {
                addLen += '0'
            }
            return str + '.' + addLen
        }
    }
}


export function changeLen(type, len) {
    let o = ''
    for (let i = 1; i < len; i++) {
      o += '0'
    }
    type.toString().length < len ? type = o + type : type = type
    return type
  }
  
export function changeMoneyType(money, val) {    //转化金额单位  
    if (money || money === 0) {
      let money1 = parseFloat(money) / val
      return keepPoint(money1, 2)
    } 
  }